import Vue from 'vue'
import VueRouter from 'vue-router'
import Storage from "@/utils/storage";

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'login',
        component: () => import('../views/Login.vue')
    },
    {
        path: '/home',
        name: 'home',
        component: () => import('../views/Home.vue'),
        meta: {
            navTitle: '首页',
            requireAuth: true
        }
    },
    {
        path: '/userList',
        name: 'userList',
        component: () => import('../views/userManage/UserList.vue'),
        meta: {
            navTitle: '用户信息列表',
            requireAuth: true
        }
    },
    {
        path: '/cattleOrderList',
        name: 'cattleOrderList',
        component: () => import('../views/orderManage/CattleOrderList.vue'),
        meta: {
            navTitle: '牛采购订单',
            requireAuth: true
        }
    },
    {
        path: '/resaleOrderList',
        name: 'resaleOrderList',
        component: () => import('../views/orderManage/ResaleOrderList.vue'),
        meta: {
            navTitle: '转售记录',
            requireAuth: true
        }
    },
    {
        path: '/buyOrderList',
        name: 'buyOrderList',
        component: () => import('../views/orderManage/BuyOrderList.vue'),
        meta: {
            navTitle: '求购订单',
            requireAuth: true
        }
    },
    {
        path: '/supplyOrderList',
        name: 'supplyOrderList',
        component: () => import('../views/orderManage/SupplyOrderList.vue'),
        meta: {
            navTitle: '供货记录',
            requireAuth: true
        }
    },
    {
        path: '/fungusOrderList',
        name: 'fungusOrderList',
        component: () => import('../views/orderManage/FungusOrderList.vue'),
        meta: {
            navTitle: '黑木耳订单',
            requireAuth: true
        }
    },
    {
        path: '/resaleAuditList',
        name: 'resaleAuditList',
        component: () => import('../views/cattleAuditManage/ResaleAuditList.vue'),
        meta: {
            navTitle: '转售审核',
            requireAuth: true
        }
    },
    {
        path: '/buyAuditList',
        name: 'buyAuditList',
        component: () => import('../views/cattleAuditManage/BuyAuditList.vue'),
        meta: {
            navTitle: '求购审核',
            requireAuth: true
        }
    },
    {
        path: '/deliveryRemind',
        name: 'deliveryRemind',
        component: () => import('../views/cattleAuditManage/DeliveryRemind.vue'),
        meta: {
            navTitle: '交货期提醒',
            requireAuth: true
        }
    },
    {
        path: '/resaleExpireRemind',
        name: 'resaleExpireRemind',
        component: () => import('../views/cattleAuditManage/ResaleExpireRemind.vue'),
        meta: {
            navTitle: '转售订单到期提醒',
            requireAuth: true
        }
    },
    {
        path: '/logisticsList',
        name: 'logisticsList',
        component: () => import('../views/logisticsManage/LogisticsList.vue'),
        meta: {
            navTitle: '物流列表',
            requireAuth: true
        }
    },
    {
        path: '/balanceList',
        name: 'balanceList',
        component: () => import('../views/financeManage/BalanceList.vue'),
        meta: {
            navTitle: '账户余额流水',
            requireAuth: true
        }
    },
    {
        path: '/withdrawTrialList',
        name: 'withdrawTrialList',
        component: () => import('../views/financeManage/WithdrawTrialList.vue'),
        meta: {
            navTitle: '提现初审',
            requireAuth: true
        }
    },
    {
        path: '/withdrawReviewList',
        name: 'withdrawReviewList',
        component: () => import('../views/financeManage/WithdrawReviewList.vue'),
        meta: {
            navTitle: '提现复审',
            requireAuth: true
        }
    },
    {
        path: '/cattleProjectList',
        name: 'cattleProjectList',
        component: () => import('../views/projectManage/CattleProjectList.vue'),
        meta: {
            navTitle: '牛标的管理',
            requireAuth: true
        }
    },
    {
        path: '/fungusProjectList',
        name: 'fungusProjectList',
        component: () => import('../views/projectManage/FungusProjectList.vue'),
        meta: {
            navTitle: '黑木耳项目管理',
            requireAuth: true
        }
    },
    {
        path: '/fungusgrade',
        name: 'fungusgrade',
        component: () => import('../views/projectManage/FungusGrade.vue'),
        meta: {
            navTitle: '木耳等级配置',
            requireAuth: true
        }
    },
    {
        path: '/bannerList',
        name: 'bannerList',
        component: () => import('../views/applyManage/BannerList.vue'),
        meta: {
            navTitle: 'banner配置',
            requireAuth: true
        }
    },
    {
        path: '/platformNewsList',
        name: 'platformNewsList',
        component: () => import('../views/applyManage/PlatformNewsList.vue'),
        meta: {
            navTitle: '平台资讯配置',
            requireAuth: true
        }
    },
    {
        path: '/farmVideoList',
        name: 'farmVideoList',
        component: () => import('../views/applyManage/FarmVideoList.vue'),
        meta: {
            navTitle: '牧场视频配置',
            requireAuth: true
        }
    },
    {
        path: '/feedbackList',
        name: 'feedbackList',
        component: () => import('../views/applyManage/FeedbackList.vue'),
        meta: {
            navTitle: '意见反馈中心',
            requireAuth: true
        }
    },
    {
        path: '/operateDataList',
        name: 'operateDataList',
        component: () => import('../views/dataManage/OperateDataList.vue'),
        meta: {
            navTitle: '运营数据统计',
            requireAuth: true
        }
    },
    {
        path: '/roleList',
        name: 'roleList',
        component: () => import('../views/systemManage/RoleList.vue'),
        meta: {
            navTitle: '角色管理',
            requireAuth: true
        }
    },
    {
        path: '/roleOperate',
        name: 'roleOperate',
        component: () => import('../views/systemManage/RoleOperate.vue'),
        meta: {
            navTitle: '角色管理',
            requireAuth: true
        }
    },
    {
        path: '/accountList',
        name: 'accountList',
        component: () => import('../views/systemManage/AccountList.vue'),
        meta: {
            navTitle: '账号管理',
            requireAuth: true
        }
    },
    {
        path: '/backLogList',
        name: 'backLogList',
        component: () => import('../views/systemManage/BackLogList.vue'),
        meta: {
            navTitle: '后台日志',
            requireAuth: true
        }
    },
    {
        path: '/personalInfo',
        name: 'personalInfo',
        component: () => import('../views/PersonalInfo.vue'),
        meta: {
            navTitle: '个人信息',
            requireAuth: true
        }
    }
]

// 解决点击同一路由控制台报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
    routes
})

// 登录拦截
router.beforeEach((to, from, next) => {
	if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
		if (Storage.get("token")) { // 判断当前的token是否存在
			next();
		} else {
			next({
				path: '/',
				query: {
					redirect: '/'
				}
			})
		}
	} else {
		next();
	}
});

export default router
